#include "statusbar.h"

Statusbar::Statusbar(WINDOW *win)
{
	this->parentWindow = win;
	this->statusbar = subwin(win, 1, COLS, LINES - 1, 0);
	keypad(this->statusbar, true);
}

Statusbar::~Statusbar()
{
	delwin(this->statusbar);
}

void Statusbar::update(int line, int column)
{

	//mvwin(this->statusbar, LINES - 1, 0);
	switch(this->mode)
	{
		case commandMode:
			wclear(this->statusbar);
			wprintw(this->statusbar, "                            %d , %d", line + 1, column + 1);
			wrefresh(this->statusbar);
			break;
		case insertMode:
			wclear(this->statusbar);
			wprintw(this->statusbar, "--Insert--                  %d , %d", line + 1, column + 1);
			wrefresh(this->statusbar);
			break;
		case lineMode:
			wrefresh(this->statusbar);
			break;
	}
}

void Statusbar::changeMode(int mode)
{
	this->mode = mode;
	switch(mode)
	{
		case commandMode:
		case insertMode:
			this->getFocus(false);
			break;
		case lineMode:
			this->getFocus(true);
			break;
	}
}

void Statusbar::getFocus(bool focus)
{
	if (focus)
	{
		//touchwin(this->statusbar);
		wmove(this->statusbar, 0, 0);
		wclear(this->statusbar);
	}
	else
	{
		int x,y;
		getyx(this->parentWindow, y, x);
		touchwin(this->parentWindow);
		wmove(this->parentWindow, y, x);
	}
	
}

WINDOW *Statusbar::getBar()
{
	return this->statusbar;
}
